//
//  FuDaoShiPingGuanKanJiLuView.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/23.
//  Copyright © 2019 SanYi. All rights reserved.
//

#import "FuDaoShiPingGuanKanJiLuView.h"
#import "SYFuDaoShiPinHeaderView.h"
#import "SYPlayerDetailsView.h"
#import "SYFuDaoDetailsTableViewCell.h"
#import "SYPlayerViewController.h"
#import "SYPlayerDetailsTwoView.h"



#define W 500


@interface FuDaoShiPingGuanKanJiLuView () <UITableViewDelegate,UITableViewDataSource>

@property (strong, nonatomic) SYNoLabel *nolab;
//@property (nonatomic, strong) SYPlayerClassModel *model;
@property (nonatomic, strong) NSMutableArray *bigArray;//数据源
@property (nonatomic, strong) NSMutableArray *smallArray;
@property (strong, nonatomic) NSArray *titleArr;//编辑信息标题arr
@property (strong, nonatomic) NSArray *contArr;//内容
@property (strong, nonatomic) UITableView *curTableView;
@property (strong, nonatomic) SYFuDaoShiPinHeaderView *fdspHeaderView;//表头
@property (strong, nonatomic) UIView *contView;
//@property (strong, nonatomic) UIView *fgxView;



@end


@implementation FuDaoShiPingGuanKanJiLuView

- (instancetype)initWithFrame:(CGRect)frame{
    if ([super initWithFrame:frame]) {
//        [self initSubView];
        [self layout];
    }
    return self;
}

- (void)requestClassId:(NSString *)classId {
    [MBProgressHUD mj_showMessage:nil toView:self];
    __weak typeof(self) weakSelf = self;
    
    [SYRequestAPI fd_requestZaiXianClassTutorRecordClassId:classId success:^(NSMutableArray *listArr) {
        if (listArr.count>0) {
            weakSelf.bigArray = listArr;
            [weakSelf initSubView];
        }
        [MBProgressHUD mj_hideHUDForView:self];
        [weakSelf.curTableView reloadData];
        
    } fail:^(NSError *error) {
        [MBProgressHUD mj_hideHUDForView:self];
        [MBProgressHUD zr_showError:error.message];
        
    }];
}

- (void)initSubView {

    [self addSubview:self.navView];
    [_navView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.top.equalTo(@0);
        make.height.equalTo(@44);
    }];
    
    self.contView = [[UIView alloc] init];
    self.contView.frame = CGRectMake(self.frame.size.width/2-W/2, 44, W, 45+40*7);
//    self.contView.backgroundColor = [UIColor redColor];
    
    UILabel *titleLab = [UILabel titleColour:[UIColor colorWithHexString:@"#20B097"] titleFount:14 pingfang:@"PingFang-SC-Regular" alignment:NSTextAlignmentCenter titleLine:1];
    titleLab.text = @"班级信息";
    [self.contView addSubview:titleLab];
    
    [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contView.mas_top).offset(13);
        make.centerX.equalTo(self.contView.mas_centerX);
    }];
    
    //分割线
    UIView *fgxView = [[UIView alloc] init];
    fgxView.backgroundColor = [UIColor colorWithHexString:@"#cccccc"];
    [self.contView addSubview:fgxView];
    [fgxView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(titleLab.mas_bottom).offset(13);
        make.left.right.equalTo(self.contView);
        make.height.mas_equalTo(1);
    }];
    
    
    _titleArr = @[@"班级名称:",@"辅导老师:",@"助教:",@"辅导类型:",@"状态:",@"辅导内容:"];
    SYPlayerClassModel *classModel = self.bigArray.firstObject;
    NSArray *contArr = @[classModel.title,classModel.accountName,classModel.tutorAccountName,classModel.typeName,classModel.statusName,classModel.content];
    FDSPGKJLClassInfoView *classView = nil;
    for (int i =0; i<6; i++) {
        NSString *titleStr = _titleArr[i];
        FDSPGKJLClassInfoView *view = [[FDSPGKJLClassInfoView alloc] init];
        view.nameLabel.text = titleStr;
        view.detailLabel.text = contArr[i];
        [self.contView addSubview:view];
        
        
        if (i == 0) {
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerX.equalTo(self.contView.mas_centerX);
                make.top.equalTo(self.contView.mas_top).offset(45);
                make.width.mas_equalTo(W);
                make.height.mas_equalTo(44);
            }];
            
        } else {
            [view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerX.equalTo(self.contView.mas_centerX);
                make.top.equalTo(classView.mas_bottom);
                make.width.mas_equalTo(W);
                make.height.mas_equalTo(44);
            }];
            
            
        }
        
        classView = view;
    }
    
    

    [self addSubview:self.curTableView];
    [self.curTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.navView.mas_bottom);
        make.bottom.equalTo(self);
        make.left.equalTo(self.mas_left).offset(40);
        make.right.equalTo(self.mas_right).offset(-40);
    }];
    
    self.curTableView.tableHeaderView = self.contView;
    
    [self.curTableView registerCellWithNIbNames:@[@"SYFuDaoDetailsTableViewCell"]];
    
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    if (self.bigArray.count == 0) {
        return 0;
    } else {
        SYPlayerClassModel *playerModel = self.bigArray.firstObject;
        return playerModel.dataTutorArr.count;
    }
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    SYPlayerClassModel *playerModel = self.bigArray.firstObject;
    return playerModel.dataTutorArr.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    SYPlayerClassModel *playerModel = self.bigArray.firstObject;
    SYDataTutorModel *tutorModel = playerModel.dataTutorArr[indexPath.row];
    return (tutorModel.dataStudentArr.count+1) * 45;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return 130;
    } else {
        return 40;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.0001;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    SYFuDaoDetailsTableViewCell *detalsCell = [tableView dequeueReusableCellWithIdentifier:@"SYFuDaoDetailsTableViewCell" forIndexPath:indexPath];
    SYPlayerClassModel *playerModel = self.bigArray.firstObject;
    SYDataTutorModel *tutorModel = playerModel.dataTutorArr[indexPath.row];
    detalsCell.dataArr = tutorModel.dataStudentArr;
    
    return detalsCell;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    SYPlayerClassModel *playerModel = self.bigArray.firstObject;
    SYDataTutorModel *tutorModel = playerModel.dataTutorArr[section];
    if (section == 0) {
        SYPlayerDetailsView *playerDetailsView = [[NSBundle mainBundle] loadNibNamed:@"SYPlayerDetailsView" owner:nil options:nil].firstObject;
        
        playerDetailsView.keciLab.text = tutorModel.lessonTimes;
        playerDetailsView.kaishiLab.text = tutorModel.beginDate;
        playerDetailsView.jieshuLab.text = tutorModel.endDate;
        playerDetailsView.zhuangtaiLab.text = tutorModel.statusName;
        playerDetailsView.kaoqinLab.text = [NSString stringWithFormat:@"%@/%@",tutorModel.attendStudents,tutorModel.totalstudents];
        
        playerDetailsView.block = ^{
            [self playerVcUrl:tutorModel.videoPath];
        };
        return playerDetailsView;
    } else {
        SYPlayerDetailsTwoView *twoView = [[NSBundle mainBundle] loadNibNamed:@"SYPlayerDetailsTwoView" owner:nil options:nil].firstObject;
        twoView.keciLab.text = tutorModel.lessonTimes;
        twoView.kaishiLab.text = tutorModel.beginDate;
        twoView.jieshuLab.text = tutorModel.endDate;
        twoView.zhuangtaiLab.text = tutorModel.statusName;
        twoView.kaoqinLab.text = [NSString stringWithFormat:@"%@/%@",tutorModel.attendStudents,tutorModel.totalstudents];
        
        twoView.block = ^{
            [self playerVcUrl:tutorModel.videoPath];
        };
        
        return twoView;
    }
    return nil;
}

- (void)playerVcUrl:(NSString *)urlStr {
    SYPlayerViewController *playerVC = [[SYPlayerViewController alloc] init];
    playerVC.modalPresentationStyle = UIModalPresentationOverFullScreen;
    playerVC.urlStr = SYStringWithPickFormat(kSYWebViewUrlDefent, urlStr);
   
    [self.vc presentViewController:playerVC animated:YES completion:nil];
}



- (ZXFDCCVNav *)navView{
    if (!_navView) {
        ZXFDCCVNav *view = [[ZXFDCCVNav alloc]init];
        view.backgroundColor = MAINBACKCOLOR;
        view.delegate = self;
        view.titleLabe.text = @"辅导视频观看记录";
        _navView = view;
    }
    return _navView;
}
- (void)backClick{
    [UIView animateWithDuration:0.5 animations:^{
        self.frame = CGRectMake(self.frame.size.width,0, self.frame.size.width, self.frame.size.height);
    }completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}

- (UITableView *)curTableView {
    if (!_curTableView) {
        _curTableView = [[UITableView alloc] init];
        _curTableView.delegate = self;
        _curTableView.dataSource = self;
        _curTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        
    }
    return _curTableView;
}


@end



/*

- (void)initSubView{
    _bigArray = [NSMutableArray new];
    _smallArray = [NSMutableArray new];
    [self addSubview:self.navView];
    [self addSubview:self.mainScrollView];
    [_mainScrollView addSubview:self.classInformationHeader];
    _titleArr = @[@"班级名称:",@"辅导老师:",@"助教:",@"辅导类型:",@"状态:",@"辅导内容:"];
    for (int i =0; i<6; i++) {
        NSString *titleStr = _titleArr[i];
        FDSPGKJLClassInfoView *view = [[FDSPGKJLClassInfoView alloc]initWithFrame:CGRectMake(0, 45+40*i, W, 40)];
        view.nameLabel.text = titleStr;
        view.tag = 100+i;
        [_mainScrollView addSubview:view];
    }
    [_mainScrollView addSubview:self.videoLookInforHeader];
    [_mainScrollView addSubview:self.mainVideoView];
    _mainVideoView.nameArray = @[@"课次",@"开始日期",@"结束日期",@"状态",@"考勤",@"查看"];
    [_mainVideoView reloadViewLayout];
    
    
    
    _nolab = [[SYNoLabel alloc] initWithNameStr:@"" contView:self];
    [self addSonView];
}
- (void)addSonView{
    for (int i = 0; i<4; i++) {
        CGFloat Y = 4*i*40;
        FDSPGKJLVideoCellHeaderView *view = [[FDSPGKJLVideoCellHeaderView alloc]initWithFrame:CGRectMake(0,410+40*i+Y, W, 40)];
        view.nameArray = @[@"1",@"2019-01-30 18:00",@"2019-01-30 18:00",@"完成",@"2/3",@"查看"];
        [view reloadViewLayout];
        [_mainScrollView addSubview:view];
        
        
        FDDetailHeaderView *fddCellView = [[FDDetailHeaderView alloc]initWithFrame:CGRectMake(0,view.frame.size.height+view.frame.origin.y, W, 40)];
        fddCellView.backgroundColor = [UIColor clearColor];
        [_mainScrollView addSubview:fddCellView];
        fddCellView.nameArray = @[@"学号",@"姓名",@"观看日期",@"观看时长/分"];
        [fddCellView reloadViewLayout];
        for (int j = 1; j<4; j++) {
            CGFloat Yj = view.frame.size.height+view.frame.origin.y;
            FDDetailHeaderView *headerView = [[FDDetailHeaderView alloc]initWithFrame:CGRectMake(0, Yj+40*j, W, 40)];
            headerView.tag = 120+j;
            [_mainScrollView addSubview:headerView];
            headerView.baseView.backgroundColor = [UIColor whiteColor];
            headerView.nameArray = @[@"1",@"大大哥",@"2019/01/02 15:30:23",@"100/200"];
            [headerView reloadViewLayout];
        }
    }
}

- (void)layout{
    [_navView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@0);
        make.right.equalTo(@0);
        make.top.equalTo(@0);
        make.height.equalTo(@44);
    }];
}
- (ZXFDCCVNav *)navView{
    if (!_navView) {
        ZXFDCCVNav *view = [[ZXFDCCVNav alloc]init];
        view.backgroundColor = MAINBACKCOLOR;
        view.delegate = self;
        view.titleLabe.text = @"辅导视频观看记录";
        _navView = view;
    }
    return _navView;
}
- (void)backClick{
    [UIView animateWithDuration:0.5 animations:^{
        self.frame = CGRectMake(self.frame.size.width,0, self.frame.size.width, self.frame.size.height);
    }completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}
- (UIScrollView *)mainScrollView{
    if (!_mainScrollView) {
        UIScrollView *scroll = [[UIScrollView alloc]init];
        scroll.backgroundColor = [UIColor whiteColor];
        scroll.frame = CGRectMake(self.frame.size.width/2-W/2, 44, W, self.frame.size.height-44);
        scroll.contentSize = CGSizeMake(0, 1200);
        _mainScrollView = scroll;
    }
    return _mainScrollView;
}
- (FDSPMainLinHeaderView *)classInformationHeader{
    if (!_classInformationHeader) {
        FDSPMainLinHeaderView *view = [[FDSPMainLinHeaderView alloc]initWithFrame:CGRectMake(0, 0, W, 40)];
        _classInformationHeader = view;
    }
    return _classInformationHeader;
}
- (FDSPMainLinHeaderView *)videoLookInforHeader{
    if (!_videoLookInforHeader) {
        FDSPMainLinHeaderView *view = [[FDSPMainLinHeaderView alloc]initWithFrame:CGRectMake(0,45+40*6, W, 40)];
        _videoLookInforHeader = view;
    }
    return _videoLookInforHeader;
}
- (FDSPGKJLVideoView *)mainVideoView{
    if (!_mainVideoView) {
        FDSPGKJLVideoView *view = [[FDSPGKJLVideoView alloc]initWithFrame:CGRectMake(0,45+40*6+45, W, 40)];
        _mainVideoView = view;
    }
    return _mainVideoView;
}
//- (FDSPGKJLVideoCellHeaderView *)sectionVideoHeaderView{
//    if (!_sectionVideoHeaderView) {
//        FDSPGKJLVideoCellHeaderView *view = [[FDSPGKJLVideoCellHeaderView alloc]initWithFrame:CGRectMake(0,90+40*8, W, 40)];
//        _sectionVideoHeaderView = view;
//    }
//    return _sectionVideoHeaderView;
//}
//- (FDDetailHeaderView *)fddCellView{
//    if (!_fddCellView) {
//        FDDetailHeaderView *view = [[FDDetailHeaderView alloc]initWithFrame:CGRectMake(0, 90+40*9, W, 40)];
//        view.backgroundColor = [UIColor clearColor];
//        _fddCellView = view;
//    }
//    return _fddCellView;
//}
*/
